// 加载图片
function loadImg(src) {
  const p = new Promise((resolve, reject) => {
    const img = document.createElement("img");
    img.onload = () => {
      resolve(img);
    };
    img.onerror = () => {
      const err = new Error(`图片加载失败 ${src}`);
      reject(err);
    };
    img.src = src;
  });
  return p;
}

const url1 = "https://img.mukewang.com/5a9fc8070001a82402060220-140-140.jpg";
const url2 = "https://img3.mukewang.com/5a9fc8070001a82402060220-100-100.jpg";

async function loadImg1() {
  const img1 = await loadImg(url1);
  return img1;
}

async function loadImg2() {
  const img2 = await loadImg(url2);
  return img2;
}

!(async function () {
  //   // img1
  //   const img1 = await loadImg(url1);
  //   console.log(img1.height, img1.width);

  //   // img2
  //   const img2 = await loadImg(url2);
  //   console.log(img2.height, img2.width);

  const img1 = await loadImg1();
  console.log(img1.height, img1.width);

  const img2 = await loadImg2();
  console.log(img2.height, img2.width);
})();
